home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / saks / lns1b1.cpp < prev    next >
C/C++ Source or Header  |  1994-02-09  |  649b  |  41 lines

  1.  
  2. ----------
  3.  
  4. Listing 7 - member function definitions for lns using a pair of pointers
  5.  
  6. //
  7. // lns1b.cpp - line number sequence implementation
  8. //
  9. #include <stdio.h>
  10.  
  11. #include "lns.h"
  12.  
  13. lns::lns(unsigned n)
  14.     {
  15.     first = last = new node(n);
  16.     }
  17.  
  18. lns::~lns()
  19.     {
  20.     node *p;
  21.     while ((p = first) != 0)
  22.         {
  23.         first = first->next;
  24.         delete p;
  25.         }
  26.     }
  27.  
  28. void lns::add(unsigned n)
  29.     {
  30.     if (last->number != n)
  31.         last = last->next = new node(n);
  32.     }
  33.  
  34. void lns::print()
  35.     {
  36.     node *p;
  37.     for (p = first; p != 0; p = p->next)
  38.         printf("%4d ", p->number);
  39.     }
  40.  
  41.